import 'package:flutter/material.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:zhaoxiaowu_app/components/view.dart';
import 'package:zhaoxiaowu_app/global/global.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class MenuView extends StatefulWidget {
  @override
  _MenuViewState createState() => _MenuViewState();
}

class _MenuViewState extends State<MenuView> {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(
        "菜单",
        actions: [
          IconButton(
            icon: Icon(Icons.settings),
            onPressed: () {
              Navigator.of(context).pushNamed("theme");
            },
          )
        ],
      ),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: [
            UserAccountsDrawerHeader(
              accountName: Text(
                "陶拾幺",
                style: TextStyle(fontSize: 26.0),
              ),
              accountEmail: Text("442397045@qq.com"),
            ),
            ListTile(
              title: Text("支出上限"),
              trailing: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text((Global.shared().user?.money ?? 0.0).toString()),
                  Icon(Icons.navigate_next),
                ],
              ),
              onTap: () {},
            ),
            Divider(height: 1),
            ListTile(
              title: Text("注册时间"),
              trailing: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text((Global.shared().user?.date ?? "").toString()),
                  Icon(Icons.navigate_next),
                ],
              ),
              onTap: () => Navigator.pop(context),
            ),
            Divider(height: 1),
            ListTile(
              title: Text("退出登录"),
              trailing: Icon(Icons.exit_to_app),
              onTap: () async {
                SharedPreferences sp = await SharedPreferences.getInstance();
                sp.remove("token");
                sp.remove("user");

                Navigator.of(context).pop();
                Navigator.of(context).popAndPushNamed("/");
              },
            ),
            Divider(height: 1),
          ],
        ),
      ),
      body: Column(
        children: [
          Container(
            height: 300.0,
            child: Swiper(
              itemBuilder: (BuildContext context, int index) {
                return new Image.network(
                  "http://via.placeholder.com/350x150",
                  fit: BoxFit.fill,
                );
              },
              itemCount: 3,
              pagination: SwiperPagination(),
              control: SwiperControl(),
            ),
          ),
          SizedBox(height: 16.0.h),
          ElevatedButton(
            child: Text("记账"),
            onPressed: () => Navigator.of(context).pushNamed("accounting"),
          ),
          SizedBox(height: 16.0.h),
          Container(
            width: double.infinity,
            child: ElevatedButton(
              child: Text("恋爱记录"),
              onPressed: () => Navigator.of(context).pushNamed("loveImage"),
            ),
          ),
        ],
      ),
    );
  }
}
